﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Studio
{
	// Token: 0x02000560 RID: 1376
	public class DragObject : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler, IPointerDownHandler, IEventSystemHandler
	{
		// Token: 0x1700043E RID: 1086
		// (get) Token: 0x06002312 RID: 8978 RVA: 0x000D427C File Offset: 0x000D247C
		protected Canvas canvas
		{
			get
			{
				if (this.m_Canvas == null)
				{
					this.m_Canvas = base.GetComponentInParent<Canvas>();
				}
				return this.m_Canvas;
			}
		}

		// Token: 0x1700043F RID: 1087
		// (get) Token: 0x06002313 RID: 8979 RVA: 0x000D42A4 File Offset: 0x000D24A4
		protected RectTransform rectCanvas
		{
			get
			{
				if (this.m_RectCanvas == null)
				{
					this.m_RectCanvas = (this.canvas.transform as RectTransform);
				}
				return this.m_RectCanvas;
			}
		}

		// Token: 0x17000440 RID: 1088
		// (get) Token: 0x06002314 RID: 8980 RVA: 0x000D42D4 File Offset: 0x000D24D4
		protected RectTransform rectTransform
		{
			get
			{
				if (this.m_RectTransform == null)
				{
					this.m_RectTransform = (base.transform as RectTransform);
				}
				return this.m_RectTransform;
			}
		}

		// Token: 0x06002315 RID: 8981 RVA: 0x000D4300 File Offset: 0x000D2500
		public void OnBeginDrag(PointerEventData eventData)
		{
			SortCanvas.select = this.canvas;
			Rect pixelRect = this.canvas.pixelRect;
			Vector2 sizeDelta = this.rectCanvas.sizeDelta;
			Vector2 sizeDelta2 = this.rectTransform.sizeDelta;
			Vector2 anchorMax = this.rectTransform.anchorMax;
			Vector2 pivot = this.rectTransform.pivot;
			this.rectArea.Set(sizeDelta.x * anchorMax.x + sizeDelta2.x * pivot.x, -(sizeDelta.y * anchorMax.y) + sizeDelta2.y * pivot.y, sizeDelta.x - sizeDelta2.x, sizeDelta.y - sizeDelta2.y);
			this.vecRate.x = pixelRect.width / sizeDelta.x;
			this.vecRate.y = pixelRect.height / sizeDelta.y;
		}

		// Token: 0x06002316 RID: 8982 RVA: 0x000D43F4 File Offset: 0x000D25F4
		public void OnDrag(PointerEventData eventData)
		{
			Vector2 vector = eventData.delta;
			vector.x /= this.vecRate.x;
			vector.y /= this.vecRate.y;
			vector += this.rectTransform.anchoredPosition;
			this.rectTransform.anchoredPosition = Rect.NormalizedToPoint(this.rectArea, Rect.PointToNormalized(this.rectArea, vector));
		}

		// Token: 0x06002317 RID: 8983 RVA: 0x000D4470 File Offset: 0x000D2670
		public void OnEndDrag(PointerEventData eventData)
		{
		}

		// Token: 0x06002318 RID: 8984 RVA: 0x000D4474 File Offset: 0x000D2674
		public void OnPointerDown(PointerEventData eventData)
		{
			SortCanvas.select = this.canvas;
		}

		// Token: 0x04002415 RID: 9237
		[SerializeField]
		protected Canvas m_Canvas;

		// Token: 0x04002416 RID: 9238
		protected RectTransform m_RectCanvas;

		// Token: 0x04002417 RID: 9239
		protected RectTransform m_RectTransform;

		// Token: 0x04002418 RID: 9240
		protected Rect rectArea = default(Rect);

		// Token: 0x04002419 RID: 9241
		protected Vector2 vecRate = Vector2.one;
	}
}
